import axios from '../axios.js';

const DATA_COUNT = '/user/count';
const ADMIN_LOGIN = '/user/login';
const UPLOAD_FILE = '/system/upload';

const prefix = "/api/console";
/**
 *  获取数据统计
 */
const getDataCount = ({query_time='all',start,end,day,get_data=0}) => {
    let resPar = {
        query_time
    };
    if (start) {
        resPar.start = start
    }
    if (end) {
        resPar.end = end;
    }
    if (day) {
        resPar.day = day;
    }
    if (get_data) {
        resPar = {
            get_data: 1,
        }
    }
    return axios.get(prefix + DATA_COUNT,resPar);
}
/**
 *  管理员登录
 * @param { String } name 账户名
 * @param { String } passwd 密码
 * @param { String } vercode 验证码
 */
const postAdminLogin = ({name,passwd,vercode}) => {
    let resPar = {
        name,
        passwd,
        vercode
    }
    return axios.post(prefix + ADMIN_LOGIN,resPar);
}
/**
 *  上传文件
 *  @param { Sring }  bid 时间串集
 *  @param { Object } file 上传文件对象
 */
const uploadFile = (fromData) => {
    let resPar = fromData;
    return axios.post(prefix + UPLOAD_FILE,resPar);
}
const HOME_PIC_SHOW = '/carousel/index';
/**
 *  获取首页图片展示
 */
const getHomePicShow = () => {
    return axios.get(prefix + HOME_PIC_SHOW,{});
}
/**
 *  修改首页图片展示
 */
const editHomePice = (resPar) => {
    return axios.post(prefix + HOME_PIC_SHOW,resPar);
}
// 邀请排行榜
const INVITE_RANK_LIST = '/user/inviter/order';
const INVITE_RANK_VIRTUAL_USER = '/user/fake/manage';
const inviteRankApi = {
    /**
     *  获取邀请排行榜列表
     *  @param { String } last 0本月 1 上月
     */
    getInviteRankList({last=0}) {
        return axios.get(prefix + INVITE_RANK_LIST,{last});
    },
    addRankVirtualUser({user_name,inviter_count,avatar,income}) {
        let resPar = {
            user_name,
            inviter_count,
            avatar,
            income
        };
        return axios.post(prefix + INVITE_RANK_LIST,resPar);
    },
    editVirtualUserDetail({user_id,invite_add_count=0,add_money=0}){
        let resPar = {
            user_id,
            invite_add_count,
            add_money,
            useJson: true
        };
        return axios.post(prefix + INVITE_RANK_VIRTUAL_USER,resPar);
    },
    // 增加排行榜用户个人数据

}
// 系统配置
const SYSTEM_CONFIG = '/system/get/config';
const PLAN_LIST = '/system/autotask/manage';
const systemConfigApi = {
    getSystemConfig() {
        return axios.get(prefix + SYSTEM_CONFIG,{});
    },
    editSystemConfig(resPar) {
        return axios.post(prefix + SYSTEM_CONFIG,resPar);
    },
    getPlanList({page=1,pagesize=10,status=0,type,keyword}) {
        let resPar = {
            page,
            pagesize,
            status,
        };
        if (keyword) {
            resPar.type = type;
            resPar.keyword = keyword;
        }
        return axios.get(prefix + PLAN_LIST,resPar);
    },
    executePlan({task_id,status}) {
        console.log(status);
        return axios.post(prefix + SYSTEM_CONFIG,{
            task_id,
            status,

        });
    }
}
// 管理员账号
const QUERY_ADMIN = '/admin/query';
const SAVE_ADMIN = '/admin/save';
const DELETE_ADMIN = '/admin/delete'
const adminApi = {
    getAdminAccount({offset=1,limit=10}) {
        return axios.get(prefix + QUERY_ADMIN,{
            offset,
            limit,
        });
    },
    editAdminAccount({admin_id=0,login_name,passwd,qq,mobile}) {
        let resPar = {
            admin_id,
            login_name,
            passwd,
            useJson: true
        };
        if (admin_id == 0 ) {
            resPar.role_ids = '[1]';
        }
        if (qq) {
            resPar.qq = qq;
        }
        if (mobile) {
            resPar.mobile = mobile;
        }
        return axios.post(prefix + SAVE_ADMIN,resPar);
    },
    deleteAdminAccount({admin_id}) {
        return axios.post(prefix + DELETE_ADMIN,{
            admin_id,
            useJson: true
        });
    },
    getHotword() {
      return axios.get(prefix)
    },
}

//运营配置
const MARKET_HOTSEARCH = '/system/hot_search'
const DAILY_TASK = '/task/daily_task/show'
const marketApi = {
    getMarkeyHotWord() {
        return axios.get(prefix + MARKET_HOTSEARCH);
    },
    setMarkeyHotWord(hotWord) {
        return axios.post(prefix + MARKET_HOTSEARCH, hotWord);
    },
    getMarkeyTaskshow() {
        return axios.get(prefix + DAILY_TASK);
    },
    setMarkeyTaskshow(data) {
        return axios.post(prefix + DAILY_TASK,data);
    },
}

let stsyemApi = Object.assign({},{
    getDataCount,
    postAdminLogin,
    uploadFile,
    getHomePicShow,
    editHomePice,
},inviteRankApi,systemConfigApi,adminApi,marketApi,);

export default stsyemApi;
